﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace BaoJian.eshop
{
  
    public partial class detail : System.Web.UI.Page
    { 
        private WebProfile Profile
        {
            get { return new WebProfile(Context.Profile); }
        }
        private string PID = null;
        public LYQ.Model.EProduct eproduct = null;
        public LYQ.Model.Product product = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            PID = HttpContext.Current.Request.QueryString["PID"];
            if (PID != null)
            {

                LYQ.BLL.EProduct eproductBll = new LYQ.BLL.EProduct();
                LYQ.BLL.Product productBll = new LYQ.BLL.Product();

                eproduct = eproductBll.GetModel(new Guid(PID));
                product = productBll.GetModel(new Guid(PID));

                Image1.ImageUrl = eproduct.ImagePath;
            }
        }      
        protected void Buy_Click(object sender, ImageClickEventArgs e)
        {
            string u = Profile.UserName;
            int pos = Profile.CustomerSelect.IndexOf(PID);

            if( pos != -1)  //已经选购该商品
            {
                int pos1 = Profile.CustomerSelect.IndexOf(",", pos);
                int pos2 = Profile.CustomerSelect.IndexOf(";",pos1);
                string tmp;
                if (pos2 == -1)  //第一个选购的商品
                {
                    tmp = Profile.CustomerSelect.Substring(pos1 + 1);
                    Profile.CustomerSelect = Profile.CustomerSelect.Remove(pos);
                    Profile.CustomerSelect += PID + "," + NUM.Value;
                }
                else //选购其他商品
                {
                    tmp = Profile.CustomerSelect.Substring(pos, pos2 - pos);
                    Profile.CustomerSelect = Profile.CustomerSelect.Replace(tmp, PID + "," + NUM.Value);
                }
             }
            else  //没有选购该商品
            {
                if (Profile.CustomerSelect != "") //选购其他商品
                {
                    Profile.CustomerSelect += ";"+ PID + "," + NUM.Value;
                }
                else                             //第一个选购的商品
                {
                    Profile.CustomerSelect = PID + "," + NUM.Value;
                }
            }
            SuccessedAdd.Visible = true;         
        }
    }
}
